package client;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LockPanel extends JPanel{
    private static final long serialVersionUID = 1L;

    Client client;
	JButton submitButton;
	
	public LockPanel(Client client){
		this.client = client;
		
		// Create elements
		JPanel linePanel = new JPanel();
	    JLabel user = new JLabel("Username :");
	    JTextField userTx = new JTextField();
	    JLabel pass = new JLabel("Password :");
	    JTextField passTx = new JTextField();
	    JLabel empty = new JLabel("");
		submitButton = new JButton("Submit");
		
		// Self setup
		this.setBorder(BorderFactory.createLineBorder(Color.gray, 2));
		this.setLayout(null);
		
		// Panel setup
		linePanel.setBounds(2,2,196, 96);   
        linePanel.setBorder(BorderFactory.createMatteBorder(15, 15, 15, 15, Color.white));
        linePanel.setBackground(Color.white);
        linePanel.setLayout(new GridLayout(3,2,5,5));
        
        // User setup
        int width = 196/2-5;
        int height = 96/3-10;
        user.setBounds(15, 15, width, height);
        userTx.setBounds(15+width+5, 15, width, height);
		
		// Assemble
		linePanel.add(user);
		linePanel.add(userTx);
		linePanel.add(pass);
		linePanel.add(passTx);
		linePanel.add(empty);
		linePanel.add(submitButton);
	    this.add(client.loginPanel);
		
		// Add listeners
		submitButton.addActionListener(new SubmitAction());
	}
	
	private class SubmitAction implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			client.unlock();
		}
	}
}
